---
import BaseLayout from "../layouts/BaseLayout.astro"
import globalData from "../../../build/data/index.mjs"
const { year } = globalData
---

<BaseLayout childpage backtotop>
  <div class="container-fluid">
    <div class="row g-3">
      <div class="col">
        <div class="card border-0 shadow-sm">
          <div class="card-header bg-body">网站设置</div>
          <div class="card-body">
            <form id="form">
              <div class="row mb-3">
                <label
                  for="sitename"
                  class="col-sm-2 col-form-label text-sm-end">网站名称</label
                >
                <div class="col-sm-10">
                  <input
                    type="text"
                    class="form-control"
                    id="sitename"
                    name="sitename"
                    value="adminlts"
                  />
                </div>
              </div>
              <div class="row mb-3">
                <label for="domain" class="col-sm-2 col-form-label text-sm-end"
                  >网站域名</label
                >
                <div class="col-sm-10">
                  <input
                    type="text"
                    class="form-control"
                    id="domain"
                    name="domain"
                    value="https://www.adminlts.top"
                  />
                </div>
              </div>

              <div class="row mb-3">
                <label for="cache" class="col-sm-2 col-form-label text-sm-end"
                  >缓存时间</label
                >
                <div class="col-sm-10">
                  <div class="input-group">
                    <input
                      type="text"
                      class="form-control"
                      id="cache"
                      name="cache"
                      value="10"
                    />
                    <span class="input-group-text">分钟</span>
                  </div>
                  <div class="form-text">
                    本地开发一般推荐设置为 0,线上环境建议设置为 10
                  </div>
                </div>
              </div>

              <div class="row mb-3">
                <label for="cache" class="col-sm-2 col-form-label text-sm-end"
                  >最大文件上传</label
                >
                <div class="col-sm-10">
                  <div class="input-group">
                    <input
                      type="text"
                      class="form-control"
                      id="cache"
                      name="cache"
                      value="2048"
                    />
                    <span class="input-group-text">KB</span>
                  </div>
                  <div class="form-text">提示:1 M = 1024 KB</div>
                </div>
              </div>

              <div class="row mb-3">
                <label
                  for="upfiletype"
                  class="col-sm-2 col-form-label text-sm-end"
                  >上传文件类型</label
                >
                <div class="col-sm-10">
                  <input
                    type="text"
                    class="form-control"
                    id="upfiletype"
                    name="upfiletype"
                    value="png|gif|jpg|jpeg|zip|rar"
                  />
                </div>
              </div>

              <div class="row mb-3">
                <label for="title" class="col-sm-2 col-form-label text-sm-end"
                  >首页标题</label
                >
                <div class="col-sm-10">
                  <textarea
                    class="form-control"
                    id="title"
                    rows="3"
                    name="title">adminlts 通用后台管理模板系统</textarea
                  >
                </div>
              </div>
              <div class="row mb-3">
                <label
                  for="keywords"
                  class="col-sm-2 col-form-label text-sm-end">META关键词</label
                >
                <div class="col-sm-10">
                  <textarea
                    class="form-control"
                    id="keywords"
                    rows="3"
                    name="keywords"
                    placeholder="多个关键词用英文逗号分隔"
                    >响应式,后台管理模板,bootstrap5</textarea
                  >
                </div>
              </div>
              <div class="row mb-3">
                <label
                  for="descript"
                  class="col-sm-2 col-form-label text-sm-end">META描述</label
                >
                <div class="col-sm-10">
                  <textarea
                    class="form-control"
                    id="descript"
                    rows="3"
                    name="descript"
                    >adminlts是基于bootstrap(5.1.3+)的通用型后台模板解决方案</textarea
                  >
                </div>
              </div>

              <div class="row mb-3">
                <label
                  for="copyright"
                  class="col-sm-2 col-form-label text-sm-end">版权信息</label
                >
                <div class="col-sm-10">
                  <textarea
                    class="form-control"
                    id="copyright"
                    rows="3"
                    name="copyright"
                    >Copyright © {year}. All right reserved.</textarea
                  >
                </div>
              </div>

              <div class="row mb-3">
                <div class="col-sm-10 offset-sm-2">
                  <button type="submit" class="btn btn-primary">确认修改</button
                  >
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script
    is:inline
    slot="script"
    src="https://cdn.jsdelivr.net/gh/ajiho/formvalidation@main/dist/js/formValidation.js"
  ></script>
  <script
    is:inline
    slot="script"
    src="https://cdn.jsdelivr.net/gh/ajiho/formvalidation@main/dist/js/framework/bootstrap.js"
  ></script>
  <script
    is:inline
    slot="script"
    src="https://cdn.jsdelivr.net/gh/ajiho/formvalidation@main/dist/js/language/zh_CN.js"
  ></script>

  <script is:inline slot="js">
    //前端表单验证
    $("#form")
      .formValidation({
        fields: {
          keywords: {
            validators: {
              notEmpty: true,
            },
          },
        },
      })
      .on("success.form.fv", function (e) {
        //阻止表单提交
        e.preventDefault()
        //得到表单对象
        const $form = $(e.target)
        const data = $form.serialize()

        //ajax请求
        $.ajax({
          url: "/sys/website",
          method: "put",
          data,
        }).then(function (response) {
          if (response.code === 200) {
            $.toasts.success()
          }
        })
      })
  </script>
</BaseLayout>
